#@head("组织机构列表")
#define main()
#end
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">名称</label>
								<div class="layui-input-block">
									<input type="text" name="attr.name" placeholder="请输入名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-org" lay-submit lay-filter="LAY-org-front-search">查询</button>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div style="padding-bottom: 10px;">
							<button class="layui-btn layuiadmin-btn-org" data-type="add">添加</button>
						</div>
						<table id="LAY-system-org-manage" lay-filter="LAY-system-org-manage">
						</table>
						<script type="text/html" id="table-system-org-operate">
							<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
							<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			  			</script>
					</div>
				</div>
			</div>
		</div>
	</div>
	#@layui()
	#define use()
		use(["index", "form", "table"], function(){
			var $ = layui.$,
			form = layui.form,
			table = layui.table,
			a = layui.admin;
			
			table.render({
		        elem: "#LAY-system-org-manage",
		        url: layui.setter.base + "/system/org/list",
		        cellMinWidth: 80,
		        cols: [[
			        {type: "checkbox", fixed: "left"},
			        {field: "id", title: "ID", width: 100, sort: !0},
			        {field: "parentName", title: "上级机构"},
			        {field: "name", title: "机构名称"},
			        {field: "code", title: "机构编码"},
			        {field: "contacts", title: "联系人", width: 150},
			        {field: "phone", title: "联系人电话"},
			        {field: "email", title: "联系人电邮箱"},
			        {field: "status", title: "状态", width: 100, templet: function(d){
			        	if(d.status == 0){
			        		return "停用";
		                }else if(d.status == 1){
		                	return "启用";
		                }
			        }},
			        {title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#table-system-org-operate"}
		        ]],
		        page: {
			        layout: ["limit", "count", "prev", "page", "next", "skip"], //自定义分页布局
			        groups: 1, //只显示 1 个连续页码
			        first: false, //不显示首页
			        last: false //不显示尾页
		        },
		        limit: 30,
		        height: "full-220",
		        skin: "row", //行边框风格
		        even: true, //开启隔行背景
		        text: {
		            none: "暂无相关数据"
		        }
		    }),
		    table.on("tool(LAY-system-org-manage)", function(e) {
		        var data = e.data;
		        if ("del" === e.event) {
		            layer.confirm("真的删除行么", function(t) {
		            	a.req({
				            url: layui.setter.base + "/system/org/delete",
		                    data: {"ids": data.id},
		                    done: function(res){
		            			layer.msg(res.msg, {icon: 1});
		   						table.reload("LAY-system-org-manage");
		                        layer.close(t)
		   					}
				        });
		            });
		        } else if ("edit" === e.event) {
		            layer.open({
		                type: 2,
		                title: "编辑组织机构",
		                content: layui.setter.base + "/system/org/form?id=" + data.id,
		                maxmin: true,
		                area: ["700px", "300px"],
		                btn: ["确定", "取消"],
		                yes: function(e, t) {
		                    var l = window["layui-layer-iframe" + e],
		                    r = "LAY-org-front-submit",
		                    n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
		                    //监听提交
		                    l.layui.form.on("submit(" + r + ")", function(t) {
		                        a.req({
		                            url: layui.setter.base + "/system/org/save",
		                            data: t.field,
		                            done: function(res){
		        						layer.msg(res.msg, {icon: 1});
		        						table.reload("LAY-system-org-manage");//数据刷新
		    	                        layer.close(e);//关闭弹层
		        					}
		                        });
		                    }),
		                    n.trigger("click");
		                },
		                success: function(e, t) {}
		            })
		        }
		    });
			
			//监听搜索
			form.on("submit(LAY-org-front-search)", function(data){
				var field = data.field;
				//执行重载
				table.reload("LAY-system-org-manage", {
					where: field
				});
			});
			
			//事件
			var active = {
				add: function(){
					layer.open({
						type: 2,
						title: "添加组织机构",
						content: layui.setter.base + "/system/org/form",
		                maxmin: true,
		                area: ["700px", "300px"],
						btn: ["确定", "取消"],
						yes: function(e, t){
							var l = window["layui-layer-iframe"+ e],
							r = "LAY-org-front-submit",
							n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
							l.layui.form.on("submit(" + r + ")", function(t){
								a.req({
									url: layui.setter.base + "/system/org/save",
									data: t.field,
									done: function(res){
										layer.msg(res.msg, {icon: 1});
										table.reload("LAY-system-org-manage");
										layer.close(e);
									}
								});
							});
							n.trigger("click");
						}
					});
				}
			};
			
			$(".layui-btn.layuiadmin-btn-org").on("click", function(){
				var type = $(this).data("type");
				active[type] ? active[type].call(this) : "";
			});
		});
	#end
</body>
</html>
